from elasticsearch import Elasticsearch

es_client = Elasticsearch(["localhost:9200"])

if __name__ == '__main__':

    # 多个条件限制的删除
    delete_options = {"query": {
        "bool": {
            "must": [{"term": {"alert_level": "critical"}},
                     {"range": {
                         "write_date": {
                             "gte": "2018-11-11",
                             "lte": "now"
                         }
                     }
                     }
                     ]
        }
    }
    }

    # 根据id删除
    delete_by_id = {"query": {"match": {"_id": "_Yon72YBncOSVgrNpmU6"}}}
    # 删除所有
    delete_by_all = {"query": {"match_all": {}}}
    result = es_client.delete_by_query(index="index_name", body=delete_by_id, doc_type="vulnerability")
    print(result)